package com.zareal.ymcc.mq.producter;

import com.alibaba.fastjson.JSON;
import com.zareal.ymcc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class VideoPushProducter {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public Boolean syncSend(MediaFile mediaFile){
        // 将文件对象转换成字符串
        String mediaFileJsonStr = JSON.toJSONString(mediaFile);
        // distinction 是 topic:tag
        SendResult sendResult = rocketMQTemplate.syncSend("video-topic:push-tag", mediaFileJsonStr);
        // 对比获取状态
        SendStatus sendStatus = sendResult.getSendStatus();
        return sendStatus.equals(SendStatus.SEND_OK);
    }
}
